Announcement

Collapse
No announcement yet.

How to make an “over” with an OSL closure

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to make an “over” with an OSL closure

    An "over" in compositing is A+B(1-a) meaning that before adding A and B, a holdout matte is made by inverting the alpha. I’m wondering how to do this in OSL with a closure, so instead of simply adding two closures together:


    Ci = spec_closure + diffuse_closure;


    The reason I want to do this is that I am trying to combine two subsurface scattering closures using an over. So assuming subsurfaceA has a small scatter radius, subsurfaceB has a large scatter radius, I want to use the “alpha” of subsurfaceA to make subsurfaceB transparent (creating a holdout matte), and then add subsurfaceA to subsurfaceB... thus doing an “over” operation rather than a “plus.”


    OSL does have a “holdout” signaling closure which appears to be made for this purpose, but the Vray docs say it does not support signaling closures. So that wont work.


    Anyone have any ideas as to how best to do this?

  • #2
    I'm thinking that perhaps I could do this with transparent() which is supported in Vray. The part that I'm stuck on is how to derive the opacity of subsurfaceA (with the smaller scatter radius), as opposed to the opacity of subsurfaceB. For example I could do this:

    Code:
    closure color over (closure color A, closure color B, color alpha)
        {
            if (alpha == 1) { return = A; } 
            else { return = A + (1-alpha) * B; } 
        }
    The problem is how to get the "alpha" from subsurfaceA. I could maybe use a luminance()

    Code:
    float Alpha = luminance(subsurfaceA);
    But I'm not sure that's really the best way to do it.
    Last edited by sharktacos; 14-05-2016, 12:06 PM.

    Comment


    • #3
      Closures don't have an alpha...

      Best regards,
      Vlado
      I only act like I know everything, Rogers.

      Comment


      • #4
        Originally posted by vlado View Post
        Closures don't have an alpha...

        Best regards,
        Vlado

        What would you suggest then to achieve an "over" in this case?

        Comment


        • #5
          The only meaningful thing you can do is blend the two closures with some predetermined blend amount: A*(1-blendAmount)+B*blendAmount

          Best regards,
          Vlado
          I only act like I know everything, Rogers.

          Comment


          • #6
            Would it work then to use the luminescence from the subsurfaceA closure for the blendAmount?

            I'm trying to layer two SSS2 materials together based on a suggestion you made this post. I can simply add them together, but then the shallow SSS color will be mixed with deep SSS color. I'd rather have artistic control so the user can have the shallow and deep colors be exactly the ones they pick. So I thought combining them with an "over" might do the trick.

            There may be a better way to approach this besides doing an "over," but my goal is to make something that has WYSIWYG colors .

            Comment


            • #7
              Closures are computed after the OSL shader is executed; the shader only collects information on which closures to evaluate and how to mix them.

              You can take a look at the way this is done in the AL shaders, for example, where three different SSS profiles are computed in such a way as to produce a given surface color. I can probably post the code reworked as OSL a bit later.

              Best regards,
              Vlado
              I only act like I know everything, Rogers.

              Comment


              • #8
                Originally posted by vlado View Post
                I can probably post the code reworked as OSL a bit later.
                Yes please, that would be awesome!

                Comment


                • #9
                  Originally posted by vlado View Post
                  You can take a look at the way this is done in the AL shaders, for example, where three different SSS profiles are computed in such a way as to produce a given surface color.
                  I downloaded the ALshaders source code. Lots of files there. So just to be sure I'm looking in the right place, are you referring to alSurface.cpp ?

                  Comment


                  • #10
                    deleting, please disregard.
                    Last edited by sharktacos; 16-05-2016, 06:04 PM.

                    Comment


                    • #11
                      are you referring to alSurface.cpp ?
                      Probably Vlado had in mind alLayer.cpp
                      Zdravko Keremidchiev | chaos.com
                      Chaos Support Representative | contact us

                      Comment


                      • #12
                        No, I didn't mean alLayer.cpp

                        Best regards,
                        Vlado
                        I only act like I know everything, Rogers.

                        Comment


                        • #13
                          Here is what the OSL code should look like, if the three sss layers were mixed exactly as in the alSurface shader; it's as simple as it gets. However I have some problem that the vray_subsurface() closure doesn't want to get multiplied by the final SSS color - Ivan is looking into it now.

                          Best regards,
                          Vlado
                          Attached Files
                          I only act like I know everything, Rogers.

                          Comment


                          • #14
                            Thanks, I'll give it a try.

                            Originally posted by vlado View Post
                            I have some problem that the vray_subsurface() closure doesn't want to get multiplied by the final SSS color

                            Best regards,
                            Vlado
                            I don't think it's possible to multiply closures. Quote from Larry Gritz "An aggregate OSL closure has to be a linear combination of primitive closures. So you can't multiply two closures together."

                            This should work though:

                            Code:
                            closure color result_sss=
                                  sss_color * (vray_subsurface(1.33, 1.0, r1, weight1)+
                                  vray_subsurface(1.33, 1.0, r2, weight2)+
                                  vray_subsurface(1.33, 1.0, r3, weight3));
                                  
                                Ci=result_sss;
                            Last edited by sharktacos; 17-05-2016, 03:38 PM.

                            Comment


                            • #15
                              I'm not multiplying closures, my code is equivalent to yours, and it still won't work - the vray_subsurface() closure ignores any color it is multiplied by. Will fix it...

                              Best regards,
                              Vlado
                              I only act like I know everything, Rogers.

                              Comment

                              Working...
                              X